package com.apollow.oschina.base;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.apollow.oschina.R;
import com.apollow.oschina.adapter.TabVPAdpater;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2017/1/13 0013.
 */
public abstract class TabVPFragment extends BaseFragment {
    /*1. 滑动界面实现步骤
            * 1. 初始化布局, 将包含页面滑动标签(PageSlidngTabStrip),ViewPager的布局初始化
            PageSlidngTabStrip+ViewPager+Fragment
            * 2. 查找关心的控件
            PageSlidngTabStrip
            ViewPager
            * 3. 创建数据适配器   PagerAdapter
            FragmentPagerAdapter--> FragmentStatePagerAdapter
            * 4. 初始化ViewPager要显示的数据
            : 标签信息   标签所对应的Fragment   传递给Fragment的参数
            * 5. 将数据适配器设置给ViewPager
            * 6. 页面滑动标签(PageSlidngTabStrip)要和ViewPager要绑定/关联*/
    //通过黄油刀 声明 控件
    @BindView(R.id.tab_layout)
    TabLayout tabLayout;
    @BindView(R.id.vp_news)
    ViewPager mViewPager;
    private TabVPAdpater mAdapter;
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        /*******************与界面相关********************/

        //1. 初始化布局, 将包含页签布局(TabLayout),ViewPager的布局初始化
        //该布局要包含TabLayout+ViewPager
        View fragmentView = inflater.inflate(R.layout.fragment_news_vp, container, false);
        //2. 查找关心的控件 通过ButterKnife 实现View注入
        ButterKnife.bind(this, fragmentView);

        //3. 创建数据适配器  继承 PagerAdapter ，由于存在片段嵌套，需要传递getChildFragmentManager()
        //4. 将数据适配器设置给ViewPager
//            mViewPager.setAdapter(mAdapter);
        //5. Tablayout要和ViewPager要绑定/关联
//            tabLayout.setupWithViewPager(mViewPager);
        mAdapter = new TabVPAdpater(getChildFragmentManager(),mViewPager,tabLayout);

        //6. 初始化页签
        setupTab(mAdapter);

        return fragmentView;
    }

    //取得bundle对象
    public Bundle getBundle(String title) {
        Bundle bundle=new Bundle();
        bundle.putString("key",title);
        return bundle;
    }
    public abstract  void setupTab(TabVPAdpater adapter);


}


